package com.icss.ah.platformActivity.action;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;

import net.sf.json.JSONObject;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.icss.ah.base.action.BaseAction;
import com.icss.ah.base.bean.EasyuiDataGridJson;
import com.icss.ah.base.bean.Json;
import com.icss.ah.base.util.DateUtils;
import com.icss.ah.login.bean.UserInfoBean;
import com.icss.ah.platformActivity.service.PlatformActivityService;

/**
 * 平台活动
 *
 */
@Controller
@Scope("prototype")
public class PlatformActivityAction extends BaseAction{

	private static final long serialVersionUID = 1L;
	private final Logger errlog = Logger.getLogger("E");
	private final Logger infolog = Logger.getLogger("I");
	
	@Autowired
	private PlatformActivityService platformActivityService;
	private Json jsonText=new Json();
	
	private String activityDate;//活动时间
	private String activityName;//活动名称
	private String uuid;//平台活动uuid
	
	/**
	 * 去活动平台页面
	 * @return
	 */
	public String toActivityPage(){
		
		return "toActivityPage";
	}
	
	/**
	 * 加载平台活动列表
	 * @return
	 */
	public void getActivityList(){
		String userCode=getUserCodeFromSession();								//当前登录人员账号
		UserInfoBean userInfo=getUserInfo(userCode);							//登录人员信息
		String shopId=userInfo.getShopId();										//绑定店铺id
		
		try {
			Map<String, String> map = new HashMap<String, String>();
			map.put("startIndex", getStartIndexMysql());
			map.put("endIndex", getEndIndexMysql());
			map.put("activityDate", activityDate);
			map.put("activityName", activityName);
			map.put("shopId", shopId);
			List<Map<String, Object>> list=platformActivityService.getActivityList(map);
			Long total=platformActivityService.getActivityTotal(map);
			dataGridJson=new EasyuiDataGridJson();
			dataGridJson.setRows(list);
			dataGridJson.setTotal(total);
			infolog.info("platformActivityService|getActivityList");
		} catch (Exception e) {
			e.printStackTrace();
			errlog.error("PlatformActivityAction|异常：",e);
		}finally {
			str2Resp(JSONObject.fromObject(dataGridJson).toString());
		}
	}
	
	/**
	 * 申请活动
	 * @return
	 */
	public String approveActivity(){
		String userCode=getUserCodeFromSession();								//当前登录人员账号
		UserInfoBean userInfo=getUserInfo(userCode);							//登录人员信息
		String shopId=userInfo.getShopId();										//绑定店铺id
		
		Map<String, String> map = new HashMap<String, String>();
		map.put("APPLICATION_UUID", UUID.randomUUID().toString());
		map.put("ACTIVITY_UUID", uuid);
		map.put("SHOP_ID", shopId);
		map.put("APPLICATION_TIME", DateUtils.getCurrentDate("yyyy-MM-dd HH:mm:ss"));
		map.put("APPLICATION_STATUS", "0");//0待审核状态
		
		Boolean result=platformActivityService.approveActivity(map);
		if(result){
			jsonText.setSuccess(true);
		}else{
			jsonText.setSuccess(false);
		}
		return "jsonText";
	}

	public String getActivityDate() {
		return activityDate;
	}

	public void setActivityDate(String activityDate) {
		this.activityDate = activityDate;
	}

	public String getActivityName() {
		return activityName;
	}

	public void setActivityName(String activityName) {
		this.activityName = activityName;
	}

	public String getUuid() {
		return uuid;
	}

	public void setUuid(String uuid) {
		this.uuid = uuid;
	}

	public Json getJsonText() {
		return jsonText;
	}

	public void setJsonText(Json jsonText) {
		this.jsonText = jsonText;
	}
	
	

}
